<?php
namespace Home\Controller;
use Think\Controller;

class PrivateController extends Controller {

    public function index(){

        $PhotoCategoryModel = M('PhotoCategory');

        $type = $PhotoCategoryModel->order('rank desc')->select();

        $defaultCid = $type[0]['id'];

        $typeReturn = array();

        foreach($type as $v){

            $typeReturn[] = array(
                'name'     => $v['name'],
                'target'   => C('DOMAIN').'private/lists/cid/'.$v['id']
            );
        }

        $PhotoModel = M('Photo');

        $image = $PhotoModel->where('cid='.$defaultCid)->order('rank desc')->select();

        $imageReturn = array();

        foreach($image as $v){

            $imageReturn[] = array(
                'name'      => $v['name'],
                'imgUrl'    => C('PICDOMAIN').C('PICPATH').$v['litpic'],
                'target'    => C('DOMAIN').'private/photo/pid/'.$v['id']
            );
        }

        $jsonReturn = array(
            'type'  => $typeReturn,
            'image' => $imageReturn
        );

        $this->ajaxReturn($jsonReturn);
    }

    public function lists(){

        $cid = I('get.cid');

        $Model = M('Photo');

        $where['cid'] = $cid;

        $list = $Model->where($where)->order('rank desc')->select();

        $listReturn = array();

        foreach($list as $v){
            $listReturn[] = array(
                'name'      => $v['name'],
                'imgUrl'    => C('PICDOMAIN').C('PICPATH').$v['litpic'],
                'target'    => C('DOMAIN').'private/photo/pid/'.$v['id']
            );
        }

        $this->ajaxReturn($listReturn);

    }

    public function photo(){

        $pid = I('get.pid');

        $Model = M('PhotoItem');

        $where['pid'] = $pid;

        $list = $Model->where($where)->order('id desc')->select();

        $listReturn = array();

        foreach($list as $v){
            $listReturn[] = array(
                'imgUrl'    => C('PICDOMAIN').C('PICPATH').$v['litpic']
            );
        }

        $this->ajaxReturn($listReturn);

    }
}